<?php
require "../maths/tool_maths.php";
require "./tool_pear_graph.php";
require "../misc/tool_color.php";
require "../files/tool_files_dirs.php";
require "../array/tool_array.php";
$tool_graph=new tool_pear_graph();

$tool_graph->__set_width(500);
$tool_graph->__set_height(500);
$tool_graph->__add_title("");

$array_x=$array_y=array(0,10,20,30,40,50,60,70,100);
$tool_graph->__add_array_y($array_y);
$tool_graph->__add_array_x($array_x);
$tool_graph->__add_plot_title("diagonale");
$tool_graph->__add_plot_color("#00FF00");

/*
$array_x=array(0,25,40,65,80,100);
$array_y=array(0,20,48,70,90,100);
$tool_graph->__add_array_y($array_y);
$tool_graph->__add_array_x($array_x);
$tool_graph->__add_plot_title("diagonale");
$tool_graph->__add_plot_color("#00FF00");

$array_d1_x=array(0,20,35,60,75,100);
$array_d1_y=array(0,25,53,75,95,100);

$tool_graph->__add_array_y($array_d1_y);
$tool_graph->__add_array_x($array_d1_x);
$tool_graph->__add_plot_title("diagonale1");
$tool_graph->__add_plot_color("#AAAAAA");

$array_d2_x=array(0,30,45,70,85,100);
$array_d2_y=array(0,15,43,65,85,100);

$tool_graph->__add_array_y($array_d2_y);
$tool_graph->__add_array_x($array_d2_x);
$tool_graph->__add_plot_title("diagonale2");
$tool_graph->__add_plot_color("#aaaaaa");

$array_array[]=array(array(75,85),array(95,85));
$array_array[]=array(array(60,70),array(75,65));
$array_array[]=array(array(35,45),array(53,43));
$array_array[]=array(array(20,30),array(25,15));

foreach($array_array as $c){
 $tool_graph->__add_array_y($c[1]);
 $tool_graph->__add_array_x($c[0]);
 $tool_graph->__add_plot_title("diagonale2");
 $tool_graph->__add_plot_color("#333333");
}
*/
//$array_d1_x=array(0,55,100);
//$array_d1_y=array(0,40,100);

$k=7;
$parts=round(100/$k);
$array1_x=$array1_y=$array2_y=array();

$array1_y[]=0;
$array1_x[]=0;
$array=array();
for($i=1;$i<=$k;++$i){
  $x=$i*$parts;
  $array[]=$x;
  $array[]=$x;
}

$array_d2_y=$array;
$array_d1_x=Tool_array::array_merge(array(0),$array);
$array_d2_x=$array_d1_x;
$array_d1_y=Tool_array::array_merge(array(0,0),$array);

/*
$array_d1_x=$array_d2_x=array(0,10,10,50,50,60,60,80,80,100,100);
$array_d2_y=array(10,10,50,50,60,60,80,80,100,100);
$array_d1_y=array(0,0,10,10,50,50,60,60,80,80,100);
*/

$tool_graph->__add_array_y($array_d1_y);
$tool_graph->__add_array_x($array_d1_x);
$tool_graph->__add_plot_title("diagonale1");
$tool_graph->__add_plot_color("#AAAAAA");

$tool_graph->__add_array_y($array_d2_y);
$tool_graph->__add_array_x($array_d2_x);
$tool_graph->__add_plot_title("diagonale1");
$tool_graph->__add_plot_color("#AAAAAA");

$graph=$tool_graph->line_color00();

//$graph=$tool_graph->plot_line_regression2();

ob_start();
$graph->done();
$graph_svg=ob_get_contents();
Tool_files::file_write("./out.svg",$graph_svg);
ob_clean();
die();
/*
$tool_graph->__add_array_y($array_y);
$tool_graph->__add_array_x($array_x);
 */

$coord=tool_maths::regression_lineaire_simple($array_x,$array_y);
$first_x=reset($array_x);
$last_x=end($array_x);
$first_y=$first_x*$coord["a"]+$coord["b"];
$last_y=$last_x*$coord["a"]+$coord["b"];

$tool_graph->__add_array_x(array($first_x,$last_x));
$tool_graph->__add_array_y(array($first_y,$last_y));


$tool_graph->__add_title("test");

//$graph=$tool_graph->plot03();

$graph=$tool_graph->line01();
//$graph=$tool_graph->plot_line_regression2();

ob_start();
$graph->done();
$graph_svg=ob_get_contents();
Tool_files::file_write("./out.svg",$graph_svg);
ob_clean();

?>
